<%@page import="Eclass.EclassForm"%>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/tld/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/tld/struts-bean.tld" prefix="bean"%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Manage User</title>
<link rel="stylesheet" type="text/css" href="css/FinalProjectCSS.css"/>
<script type="text/javascript" src="table.js"></script>
<script type="text/javascript" src="js/MasterJS.js"></script>
<script type="text/javascript" src="js/testajax.js"></script>
<script type="text/javascript">
	function ubah(tes) {
		document.forms[0].updateUser.value = tes;
		flyToPage('update');
	}

	function viewDetail(id){
		var request = createRequest();			
		request.onreadystatechange=function()
		  {
		  if (request.readyState==4 && request.status==200)
		    {			  
			  var editPlace = document.getElementById("detailPlace");
 			  refreshDiv("detailPlace");
			  editPlace.setAttribute("style", "display:'';");
			  request.send(null);
		    }
		  }
		request.open("POST","/WebFinalProject/Eclass.do",true);
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 		
 		request.send("task=selectUser&modelEclass.userid=" + id); 
	}
	
	function refreshDiv(divId){
       var container = document.getElementById(divId);
       var content = container.innerHTML;
       container.innerHTML= content;
    }
</script>

<%
	if(session.getAttribute("result") != null)
	{
		String message = session.getAttribute("result").toString();
		%>
			<script type="text/javascript">
				window.alert('<%=message%>');
			</script>
		<%
		session.removeAttribute("result");
	}
%> 

</head>
<body onkeydown="javascript:disableF5(event, 'manageUser');">
	<center>
		<table width="100%" height="auto" class="bodyTable boxShadow" style="display:table;">
			<!-- Header -->
			<tr>
				<td colspan="2"><%@include file="/include/Header.jsp"%></td>
			</tr>
			
			<!-- Content -->
			<tr>
				<td rowspan="2" width="200px" class="navigationBox"><%@include file="/include/Navigation.jsp"%></td>
				<td align="left" class="headerBox blueBackground">User Management > Manage User</td>
			</tr>
			<tr>
				<td align="center" class="contentStyle" style="padding: 5px 7px;"><br>
					<html:form action="/Eclass" method="post">
						<html:hidden property="task" name="eclassForm" />
						<html:hidden property="modelEclass.userid" name="eclassForm"/>
						<html:hidden property="updateUser" name="eclassForm" />	
						<table border="0" width="95%" align="center" class="boxShadow  example table-autosort table-autofilter  table-autopage:10 table-stripeclass:alternate table-page-number:t1page table-page-count:t1pages table-filtered-rowcount:t1filtercount table-rowcount:t1allcount" id="t1">
							<thead>
								<tr class="headerBox formHeaderBackground">
									<th colspan="2" align="center" class="filterable table-sortable:default" style="padding:5px 7px;">
										User ID
									</th>
<!-- 									<th align="center" class="table-filterable table-sortable:default">Email</th> -->
									<th width="300px" align="center" class="filterable table-sortable:default">
										Fullname
									</th>
									<th width="100px" align="center" class="table-sortable:default">Active</th>
									<th width="100px" align="center" class="table-sortable:default">Logged In</th>
									<th width="100px" align="center" class="table-sortable:default">Role</th>
									<th></th>
								</tr>
								<tr>
									<th colspan="2" class="formListStyle"><input type="text" class="textStretch" style="max-height:12px;" name="filter" onkeyup="Table.filter(this,this)" /></th>
									<th class="formListStyle"><input type="text" class="textStretch" style="max-height:12px;" name="filter" onkeyup="Table.filter(this,this)" /></th>
									<th class="formListStyle table-filterable"></th>
									<th class="formListStyle table-filterable"></th>
									<th class="formListStyle table-filterable"></th>
								</tr>
							</thead>
							<tbody>
							<logic:notEmpty name="eclassForm" property="listUser">
								<logic:iterate id="listData" name="eclassForm" property="listUser">
									<tr class="formListBackground">
<%-- 										<logic:notEqual value="<bean:write name=listData property=userid/>" property="updateUser" name="eclassForm"> --%>
											<td class="formListStyle leftAlign" colspan="2"><bean:write name="listData" property="userid"></bean:write></td>
<%-- 											<td align="center" style="vertical-align: middle;"><bean:write name="listData" property="email"></bean:write></td> --%>
											<td class="formListStyle leftAlign"><bean:write name="listData" property="fullname"></bean:write></td>
											<td class="formListStyle centerAlign"><bean:write name="listData" property="active"></bean:write></td>
											<td class="formListStyle centerAlign"><bean:write name="listData" property="isloggedin"></bean:write></td>
											<td class="formListStyle centerAlign"><bean:write name="listData" property="role"></bean:write></td>
											<td class="formListStyle centerAlign">
<%-- 												<input class="input buttonStyle" type="button" value="Update" onclick="javascript:ubah('<bean:write name="listData" property="userid"/>');"> --%>
												<span id='editButton<bean:write name="listData" property="userid"/>'>
<%-- 													<img src="images/detailButton.png" title="view detail" style="cursor: pointer;" onclick="javascript:viewDetail('<bean:write name="listData" property="userid"/>');"/> --%>
<!-- 													&nbsp; -->
													<img src="images/detailButton.png" title="view detail" style="cursor: pointer;" onclick="javascript:ubah('<bean:write name="listData" property="userid"/>');"/>
												</span>
											</td>
<%-- 										</logic:notEqual> --%>
									</tr>								
								</logic:iterate>
							</logic:notEmpty>						
							<logic:empty name="eclassForm" property="listUser">
								<tr class="formListBackground">
									<td colspan="7" class="formListStyle centerAlign">Data is not found</td>
								</tr>
							</logic:empty>
							</tbody>
							<tfoot>
								<tr class="headerBox formHeaderBackground">
									<td width="80px" class="table-page:previous formListStyle" style="cursor:pointer;">&lt;&lt; Previous</td>
									<td colspan="5" style="text-align:center; vertical-align: middle;">Page <span id="t1page"></span>&nbsp;of <span id="t1pages"></span></td>
									<td width="55px" align="right" class="table-page:next formListStyle" style="cursor:pointer;">Next &gt;&gt;</td>
								</tr>
								<tr>
									<td colspan="7" align="center" class="headerBox formHeaderBackground"><span id="t1filtercount"></span>&nbsp;of <span id="t1allcount"></span>&nbsp;rows match filter(s)</td>
								</tr>
						</tfoot>
						</table>	
					<br>
					
<!--  ================================== Detail View Try ============================================ -->
					
					<div id="detailPlace" style="display:none;">
						<bean:write name="eclassForm" property="modelEclass.userid"/>
<%-- 					<%=session.getAttribute("selectUserId") %> --%>
<%-- 					<% if(session.getAttribute("selectUserId") != null) {%>	 --%>
						<logic:notEmpty name="eclassForm" property="modelEclass">								
									<table>
										<tr>
											<td>User ID</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.userid"/></td>
											<td colspan="3"></td>
										</tr>
										<tr>
											<td width="80px">Role</td>
											<td width="10px">:</td>
											<td width="150px"><bean:write name="eclassForm" property="modelEclass.role"/></td>
											<td width="80px">Last Login</td>
											<td width="10px">:</td>
											<td width="150px"><bean:write name="eclassForm" property="modelEclass.lastlogin"/></td>
										</tr>
										<tr>
											<td>Full Name</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.fullname"/></td>
											<td>Is Logged In</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.isloggedin"/></td>
										</tr>
										<tr>
											<td>Email</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.email"/></td>
											<td>Active</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.active"/></td>
										</tr>
										<tr>
											<td>Update User</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.usrupd"/></td>
											<td>Update Date</td>
											<td>:</td>
											<td><bean:write name="eclassForm" property="modelEclass.dtmupd"/></td>
										</tr>
									</table>	
						</logic:notEmpty>
<%-- 						<% session.removeAttribute("selectUserId");}  %>	 --%>
						</div>		
						
<!--  ================================== End Detail View Try ========================================= -->
				
					</html:form>
				</td>
			</tr>
			
			<!-- Footer -->
			<tr>
				<td align="center" colspan="2" class="headerBox blueBackground">&copy; OME. 2014. All Rights Reserved.</td>
			</tr>
		</table>
	</center>
</body>
</html>